<!--
    @name 工单详情
    @author haoyang.ding
    @date 2021-01-25
-->
<template>
  <div>
    <el-row>
      <el-col class="mark">
        <div>
          <!--  顶部按钮  -->
          <div class="btns-container">
            <el-button
              v-for="item in formButtons"
              :key="item.comKey"
              :fixed="true"
              :disabled="item.disabled"
              @click="item.clickEvent"
            >
              {{ item.text }}
            </el-button>
          </div>
          <!--  车辆信息  -->
          <h3 id="id1" class="filter-container filter-title">车辆信息</h3>
          <OneTableTemplate
            :dynamic-components="formInputs_1"
            :dynamic-form-fields="formField_1"
          />
          <!--  派工信息  -->
          <h3 id="id2" class="filter-container filter-title">派工信息</h3>
          <OneTableTemplate
            ref="multipleTable1"
            :dynamic-form-fields="formField_2"
            :dynamic-components="formInputs_2"
          />
          <h3 id="id3" class="filter-container filter-title">车主信息</h3>
          <!--  车主信息  -->
          <OneTableTemplate
            ref="multipleTable2"
            :dynamic-form-fields="formField_3"
            :dynamic-components="formInputs_3"
            title="车主信息"
          />
          <!--  三个文本域  -->
          <h3 id="id4" class="filter-container filter-title">客户描述</h3>
          <div class="textarea-header">
            <div class="filter-container filter-title textarea-header__item">
              客户描述
            </div>
            <div class="filter-container filter-title textarea-header__item">
              上次建议维修项目
            </div>
            <div class="filter-container filter-title textarea-header__item">
              本次建议维修项目
            </div>
          </div>
          <OneTableTemplate
            ref="multipleTable3"
            :dynamic-components="textareaInputs"
            :dynamic-form-fields="formField_4"
          />
          <!--  服务活动  -->
          <h3 id="id5" class="filter-container filter-title">服务活动</h3>

          <OneTableTemplate
            ref="table_1"
            :dynamic-table-cols="tableHeader_1"
            :dynamic-table-defult-height="tableHeight"
            :is-show-pagination="false"
            :is-show-select="false"
          />
          <!--  保养套餐/商城精品  -->
          <h3 id="id6" class="filter-container filter-title">
            保养套餐/商城精品
          </h3>
          <OneTableTemplate
            ref="table_2"
            :dynamic-table-cols="tableHeader_2"
            :dynamic-table-defult-height="tableHeight"
            :is-show-pagination="false"
          />
          <!--  维修信息  -->
          <h3 id="id7" class="filter-container filter-title">维修工时</h3>
          <!-- <div class="filter-container filter-title">维修信息</div> -->
          <!--  维修信息 表格一  -->
          <div class="mainten-table__line">
            <!-- <span class="mainten-table__line-info">维修工时</span> -->
            <span class="mainten-table__line-btns">
              <el-button
                :disabled="addPush"
                @click="addTimeChoose"
              >新增/追加</el-button>
              <el-button
                :disabled="isDel"
                @click="repairDelete"
              >删除</el-button>
            </span>
          </div>
          <OneTableTemplate
            ref="table_3_1"
            :dynamic-components="formInputs_3_1"
            :dynamic-table-cols="tableHeader_3_1"
            :dynamic-form-fields="formField_3_1"
            :is-show-pagination="false"
            :dynamic-table-defult-height="tableHeight"
            :callback-obj="callbackObj"
            :refresh-table-key="refreshTableKey1"
          >
            <template #repairGroupId="scope">
              <el-select
                v-model="scope.row['repairGroupId']"
                placeholder="维修班组选择"
                clearable
                :disabled="isOpenRepairGroup"
                @change="wareHouseChange($event, scope)"
              >
                <el-option
                  v-for="item in warehouseOptions || [
                    {
                      repairGroupId: scope.row['repairGroupId'],
                      groupName: scope.row['groupName'],
                    },
                  ]"
                  :key="item.repairGroupId"
                  :label="item.groupName"
                  :value="item.repairGroupId"
                />
              </el-select>
            </template>
            -->
            <!-- 仓位选择 -->
            <template #repairTechnician="scope">
              <el-select
                v-model="scope.row['repairTechnician']"
                placeholder="维修技师选择"
                :disabled="isOpenRepairTechnician"
                clearable
              >
                <el-option
                  v-for="item in scope.row.optionsRepair"
                  :key="item.repairGroupId"
                  :label="item.empName"
                  :value="item.repairTechnician"
                />
              </el-select>
            </template>
          </OneTableTemplate>
          <!--  维修信息 表格二  -->
          <h3 id="id8" class="filter-container filter-title">维修备件</h3>
          <div class="mainten-table__line">
            <span class="mainten-table__line-btns">
              <el-button
                :disabled="addPush"
                @click="SparePartsBounced"
              >新增/追加</el-button>
              <el-button
                :disabled="isDel"
                @click="partRepairDel"
              >删除</el-button>
            </span>
          </div>
          <OneTableTemplate
            ref="table_3_2"
            :dynamic-table-cols="tableHeader_3_2"
            :is-show-pagination="false"
            :dynamic-table-defult-height="tableHeight"
            :callback-obj="callbackObj1"
            :refresh-table-key="refreshTableKey2"
          />

          <!--  维修信息 表格三  -->
          <h3 id="id9" class="filter-container filter-title">其他项目</h3>
          <div class="mainten-table__line">
            <span class="mainten-table__line-btns">
              <el-button
                :disabled="addPush"
                @click="addOtherProjects"
              >新增/追加</el-button>
              <el-button
                :disabled="isDel"
                @click="repairOtherListDelete"
              >删除</el-button>
            </span>
          </div>
          <OneTableTemplate
            ref="table_3_3"
            :callback-obj="callbackObj2"
            :dynamic-table-cols="tableHeader_3_3"
            :is-show-pagination="false"
            :dynamic-table-defult-height="tableHeight"
            :refresh-table-key="refreshTableKey3"
          />
          <!--  费用信息  -->
          <h3 id="id10" class="filter-container filter-title">费用信息</h3>
          <OneTableTemplate
            ref="table_4"
            :dynamic-components="formInputs_4"
            :dynamic-form-fields="formField_5"
            :is-show-pagination="false"
            :is-show-select="false"
          />

          <!--  保养项目  -->
          <MImport
            :popups-visible.sync="mImportPopupsVisible"
            :data-for-form="dataForForm"
            @close="closeMImport"
            @returnData="returnData"
          />

          <!--  预约  -->
          <subscribe-select
            :appointment-time="appointmentTime"
            :popups-visible="isViewWindows"
            @event1="getAllList"
            @close="close4"
          />

          <!--  权益查询  -->
          <interestInquiry
            :dynamic-edit-row-data="equityQueryRowData"
            :popups-visible="equityQueryVisible"
            @close="close1"
          />

          <!--  维修历史  -->
          <historyQuery
            :popups-visible="historyPopupsVisible"
            :row-data="rowData"
            @close="close5"
          />

          <!--  电池追溯  -->
          <batteryQuery
            :popups-visible-battery="batteryPopupsVisible"
            :battery-data="batteryData"
            @close="close9"
          />

          <!--  召回/服务活动  -->
          <recallServiceActivit
            :popups-visible="activePopupsVisible"
            :recall-data="recallData"
            @close="close6"
            @toForward="getForwardList"
            @toServiceMain="getServiceList"
          />

          <!--  工时选择  -->
          <timeToChoose
            :dynamic-edit-row-data="timeSelectionRowData"
            :popups-visible="popupsVisibleTime"
            :chosen-list="chosenList"
            @refund-data="getVal"
            @close="close2"
          />

          <!--  选择备件弹框  -->
          <sparePartsSelection
            :dynamic-edit-row-data="spareSelectionRowData"
            :popups-visible="spareSelectionPopupsVisible"
            :popups-state="editPopupsState"
            :chosen-p-list="chosenPList"
            :pay-kind-list="payKindList"
            @refund-data="refundData2"
            @close="close"
          />

          <!--  其他项目弹框  -->
          <otherProjects
            :dynamic-edit-row-data="otherRowData"
            :popups-visible="otherProjectsPopupsVisible"
            :popups-state="otherProjectsPopupsState"
            :dynamic-api-style="'restful'"
            :chosen-o-list="chosenOList"
            @toFather="getList"
            @close="close3"
          />
        </div>
      </el-col>
      <el-col :span="3" class="maodian" style="min-width: 140px">
        <div>
          <a href="#id1" class="filter-container filter-title">车辆信息</a>
        </div>
        <div>
          <a href="#id2" class="filter-container filter-title">派工信息</a>
        </div>
        <div>
          <a href="#id3" class="filter-container filter-title">车主信息</a>
        </div>
        <div>
          <a href="#id4" class="filter-container filter-title">客户描述</a>
        </div>
        <div>
          <a href="#id5" class="filter-container filter-title">服务活动</a>
        </div>
        <div>
          <a
            href="#id6"
            class="filter-container filter-title"
          >保养套餐/商城精品</a>
        </div>
        <div>
          <a href="#id7" class="filter-container filter-title">维修工时</a>
        </div>
        <div>
          <a href="#id8" class="filter-container filter-title">维修备件</a>
        </div>
        <div>
          <a href="#id9" class="filter-container filter-title">其他项目</a>
        </div>
        <div>
          <a href="#id10" class="filter-container filter-title">费用信息</a>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import OneTableTemplate from '@/components/templates/oneTable'
import historyQuery from '@/views/se/maintenanceManagement/repairOrder/orderDetails/historyQuery'
import batteryQuery from '@/views/se/maintenanceManagement/repairOrder/orderDetails/batteryQuery'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import SubscribeSelect from './subscribeSelect.vue'
import request from '@/utils/request.js'
import { orgApis } from '@/api/caseManagementQuery'

export default {
  name: 'OrderDetails',
  components: {
    historyQuery,
    batteryQuery,
    OneTableTemplate,
    SubscribeSelect,

    sparePartsSelection: () => import('./wiSparePartsSelection.vue'),
    InterestInquiry: () =>
      import('@/views/se/maintenanceManagement/interestInquiry/index.vue'),
    timeToChoose: () => import('./wiOrderTimeChoose.vue'),
    otherProjects: () => import('./otherProjects.vue'),
    recallServiceActivit: () => import('./recallServiceActivit.vue'),
    MImport: () => import('./MImport')
  },

  mixins: [oneTableWithViewTemplateMixins],

  data() {
    return {
      tableHeight: 190,
      warehouseOptions: [],
      cacheData: {},
      dataForForm: {},
      refreshTableKey1: '0',
      refreshTableKey2: '0',
      refreshTableKey3: '0',
      reserveOrderCode: '', // 预约单号
      chosenList: [],
      chosenPList: [],
      payKindList: {},
      chosenOList: [], // 其他
      oflag: false,
      pflag: false,
      billType: null,
      isDel: false, // 删除

      recallData: {},
      otherProjectsPopupsState: '',
      rowData: {},
      batteryData: {},
      appointmentTime: {},
      wiDueAmount: 0, // 工时应收客户总费用
      partDueFee: 0, // 备件应收客户总费用
      sumOtherDueAmount: 0, // 其他应收客户总费用
      repairDueAmount: 0, // 应收客户总费用

      isOpenRepairGroup: false, // 维修班组与技师
      isOpenRepairTechnician: false, // 维修班组与技师
      spareNum: 0,
      otherNum: 0,
      addPush: true,
      timeChooseArray: [], // 工时
      spareChooseArray: [], // 备件
      otherChooseArray: [], // 其他
      carInfo: {},
      formList: {},
      otherRowData: {},
      serviceDlrId: '',
      isViewWindows: false,
      activePopupsVisible: false,
      isView: false,
      mImportPopupsVisible: false,
      spareSelectionPopupsVisible: false, // 选择备件
      editPopupsState: '', // 选择备件
      equityQueryVisible: false, // 权益查询
      popupsVisibleTime: false, // 选择工时
      otherProjectsPopupsVisible: false, // 其他项目
      historyPopupsVisible: false, // 维修历史
      batteryPopupsVisible: false, // 电池追溯

      formButtons: [
        {
          compKey: 'btnKey7',
          size: 'small',
          text: '作废',
          position: 'right',
          disabled: false,
          clickEvent: () => this.becomeVoid()
        },
        {
          compKey: 'btnKey6',
          size: 'small',
          text: '保存',
          position: 'right',
          disabled: false,
          clickEvent: () => this.saveAddEdit()
        },
        {
          compKey: 'btnKey5',
          size: 'small',
          text: '召回/服务活动',
          position: 'right',
          clickEvent: () => this.serviceAction()
        },
        {
          compKey: 'btnKey4',
          size: 'small',
          text: '保养项目',
          position: 'right',
          // disabled: true,
          clickEvent: () => this.maintenanceProgram()
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          text: '权益查询',
          position: 'right',
          disabled: true,
          clickEvent: () => {
            this.equityQuery()
          }
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          text: '维修历史',
          position: 'right',
          clickEvent: () => this.historyOpen()
        },
        {
          compKey: 'btnKey8',
          size: 'small',
          text: '预约',
          position: 'right',
          clickEvent: () => this.subscribe(),
          disabled: false
        },
        {
          compKey: 'btnKey0',
          size: 'small',
          text: '转车间',
          position: 'right',
          clickEvent: () => this.workOrderDispatch(),
          disabled: false
        },
        {
          compKey: 'btnKey8',
          size: 'small',
          text: '质检完成',
          position: 'right',
          clickEvent: () => this.qualityInspection(),
          disabled: false
        },
        {
          compKey: 'btnKey9',
          size: 'small',
          text: '电池追溯',
          position: 'right',
          clickEvent: () => this.batteryOpen(),
          disabled: false
        },
        {
          compKey: 'btnKey10',
          size: 'small',
          text: '车主确认',
          position: 'right',
          clickEvent: () => this.carConfirm(),
          disabled: false
        }
      ],
      // 车辆信息
      formInputs_1: [
        {
          compKey: 'key1',
          labelName: 'VIN码：',
          codeField: 'vin',
          textField: 'vin',
          isMul: false,
          component: () => import('@/components/se/VIN'),
          type: 'inputText',
          isMust: true,
          disabled: false
        },
        {
          compKey: 'key0',
          labelName: '车牌号：',
          codeField: 'carLicense',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          span: 6
        },
        {
          compKey: 'key2',
          labelName: '品牌：',
          codeField: 'carBrandCn',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key3',
          labelName: '车系：',
          codeField: 'carSeriesCn',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key4',
          labelName: '车型编码：',
          codeField: 'carConfigCode',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key5',
          labelName: '车型名称：',
          codeField: 'carConfigCn',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key6',
          labelName: '颜色：',
          codeField: 'carColorName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key7',
          labelName: '车辆用途：',
          codeField: 'buyCaruseName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key8',
          labelName: '行驶里程：',
          codeField: 'mileage',
          isMul: false,
          validrule: {
            isformat: /^[+]{0,1}(\d+)$/
          },
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'key9',
          labelName: '实际里程：',
          codeField: 'realMileage',
          component: () => import('@/components/org/commonInput'),
          validrule: { isformat: /^[+]{0,1}(\d+)$/, noRequire: true },
          isRequire: true,
          type: 'inputText',
          isMust: true,
          disabled: false
        },
        {
          compKey: 'key10',
          labelName: '购车日期：',
          codeField: 'saleDate',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key11',
          labelName: '销售交车日期：',
          codeField: 'deliveryDate',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        }
      ],
      formField_1: {
        vin: '',
        isOtherCar: '',
        carLicense: '',
        VIN: '',
        carBrandCn: '',
        carSeriesCn: '',
        carConfigCode: '',
        carConfigCn: '',
        carColorName: '',
        buyCaruseName: '',
        mileage: '',
        realMileage: '',
        saleDate: '',
        deliveryDate: ''
      },

      // 派工信息
      formInputs_2: [
        {
          compKey: 'key0',
          labelName: '派工单号：',
          codeField: 'repairOrderCode',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key1',
          labelName: '服务顾问：',
          codeField: 'empName',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key2',
          labelName: '送修人：',
          codeField: 'repairMan',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: false
        },
        {
          compKey: 'key3',
          labelName: '送修人电话：',
          codeField: 'repairTel',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          disabled: false,
          isMust: true
        },
        {
          compKey: 'key4',
          labelName: '到店时间：',
          codeField: 'repairTime',
          isMul: false,
          isRequire: true,
          component: () => import('@/components/org/datePicker/dateTimePick'),
          dateType: 'datetime',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          isMust: true,
          disabled: false
        },
        {
          compKey: 'key5',
          labelName: '预计交车时间：',
          codeField: 'preGetDate',
          isRequire: true,
          isMul: false,
          component: () => import('@/components/org/datePicker/dateTimePick'),
          dateType: 'datetime',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          disabled: false,
          isMust: true
        },
        {
          compKey: 'key6',
          labelName: '工单状态：',
          codeField: 'repairOrderStatusName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key7',
          labelName: '委外门店：',
          codeField: 'dlrName',
          textField: 'dlrName',
          component: () => import('@/components/org/commonSelect'),
          customObj: {
            api: orgApis.outDlrList,
            selectType: '1',
            defOptionFields: ['authorizedDlr', 'dlrName']
          },
          isMust: true,
          type: 'dropdownList',
          disabled: true
        },
        {
          compKey: 'key8',
          labelName: '救援里程：',
          codeField: 'rescueMileage',
          isMul: false,
          validrule: {
            isformat: /^[+]{0,1}(\d+)$/
          },
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          isRequire: false
        },
        {
          compKey: 'key9',
          labelName: '服务类型：',
          codeField: 'billType',
          component: () => import('@/components/wms/dropdownList/dropdownList'),
          options: [],
          isMust: true,
          type: 'dropdownList',
          isRequire: true
        }
      ],
      formField_2: {
        repairOrderCode: '',
        repairOrderId: '',
        empName: '',
        repairMan: '',
        repairTel: '',
        repairTime: '',
        preGetDate: '',
        repairOrderStatusName: '',
        repairOrderStatus: '',
        authorizedDlr: '',
        rescueMileage: '',
        empId: '',
        dlrName: '',
        billType: '',
        billTypeName: ''
      },

      // 车主信息
      formInputs_3: [
        {
          compKey: 'key0',
          labelName: '用户ID：',
          codeField: 'carCustId',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key1',
          labelName: '车主姓名：',
          codeField: 'custName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key2',
          labelName: '车主电话：',
          codeField: 'phone',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key3',
          labelName: '车主性质：',
          codeField: 'custClassName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key4',
          labelName: '证件号码：',
          codeField: 'credNo',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key5',
          labelName: '省份：',
          codeField: 'addrProvince',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key6',
          labelName: '城市：',
          codeField: 'addrCity',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key7',
          labelName: '区县：',
          codeField: 'addrCounty',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key8',
          labelName: '详细地址：',
          codeField: 'addrStreet',
          isMul: false,
          component: () => import('@/components/org/commonInput/textareaInput'),
          disabled: true,
          type: 'inputText',
          isMust: true,
          span: 18
        }
      ],
      formField_3: {
        carCustId: '',
        custName: '',
        phone: '',
        custClassCode: '',
        custClassName: '',
        credNo: '',
        addrProvince: '',
        addrCity: '',
        addrCounty: '',
        addrStreet: ''
      },

      // 客户描述
      textareaInputs: [
        {
          // 客户描述
          compKey: 'key0',
          codeField: 'csDesc',
          isMul: false,
          component: () => import('@/components/org/commonInput/textareaInput'),
          type: 'inputText',
          disabled: false,
          isMust: true,
          span: 8
        },
        {
          compKey: 'key1',
          codeField: 'scRecommendItem',
          isMul: false,
          component: () => import('@/components/org/commonInput/textareaInput'),
          disabled: true,
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'key2',
          codeField: 'recommendItem',
          isMul: false,
          component: () => import('@/components/org/commonInput/textareaInput'),
          type: 'inputText',
          disabled: false,
          isMust: true,
          span: 8
        }
      ],
      formField_4: {
        csDesc: '',
        recommendItem: '',
        scRecommendItem: ''
      },

      tableHeader_1: [
        {
          prop: 'updateControlId',
          label: '并发控制ID',
          hidden: true,
          alwaysHidden: true
        },
        {
          prop: 'controlBtn',
          label: '操作', // 操作
          codeField: 'orgName',
          width: null,
          align: 'center',
          isComponent: true,
          comps: [
            {
              compKey: 'propKey0',
              align: 'center',
              labelName: '删除',
              codeField: 'orgName',
              clickEvent: (index) => {
                this.serviceDelete(index)
              },
              component: () => import('@/components/org/linkButton')
            }
          ]
        },
        {
          label: '活动编号',
          prop: 'actionCode'
        },
        {
          label: '活动名称',
          prop: 'actionName'
        },
        {
          label: '活动类型',
          prop: 'actionTypeName'
        },
        {
          label: '开始日期',
          prop: 'beginDate'
        },
        {
          label: '结束日期',
          prop: 'endDate'
        }
      ],
      tableHeader_2: [
        {
          prop: 'controlBtn',
          label: '操作', // 操作
          codeField: 'orgName',
          width: null,
          align: 'center',
          isComponent: true,
          comps: [
            {
              compKey: 'propKey0',
              align: 'center',
              labelName: '删除',
              codeField: 'orgName',
              clickEvent: (index) => {
                this.setMealDel(index)
              },
              component: () => import('@/components/org/linkButton')
            }
          ]
        },
        {
          label: '订单号',
          prop: 'repairOrderId'
        },
        {
          label: '类别',
          prop: 'comboSaleType'
        },
        {
          label: '保养套餐/精品编码',
          prop: 'comboSaleCode'
        },
        {
          label: '保养套餐/精品名称',
          prop: 'comboSaleName'
        },
        {
          label: '使用次数/数量',
          prop: 'comboSaleCount'
        },
        {
          label: '有效日期',
          prop: 'endDate'
        },
        {
          label: '购车日期',
          prop: 'buyDate'
        }
      ],
      formInputs_3_1: [
        {
          compKey: 'compKey10',
          labelName: '维修类型：',
          codeField: 'repairTypeCode',
          textField: 'repairTypeName',
          otherField: 'payKind',
          isMul: false,
          customObj: {
            api: orgApis.repairTypeAndKind,
            defOptionFields: ['repairTypeCode', 'repairTypeName'],
            selectType: '1'
          },
          component: () => import('@/components/org/commonSelect'),
          rowFileds:
            'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
          type: 'dropdownList',
          isMust: true,
          span: 6,
          disabled: false
        }
      ],
      formField_3_1: {
        repairGroup: '',
        repairTypeCode: '', // 维修类型
        repairTypeName: '',
        payKind: ''
      },

      // 维修工时
      tableHeader_3_1:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              label: '工时编码',
              prop: 'wiCode'
            },
            {
              label: '维修内容',
              prop: 'wiName'
            },
            {
              label: '维修类型',
              prop: 'retRepairTypeName'
            },
            {
              label: '维修类别',
              prop: 'repairTypeName'
            },
            {
              label: '付费性质',
              prop: 'payKindName'
            },
            {
              label: '工时数',
              prop: 'saleWorkQty'
            },
            {
              label: '工时单价',
              prop: 'wiPrice'
            },
            {
              label: '费用合计',
              prop: 'wiAmount'
            },
            {
              label: '维修班组',
              prop: 'repairGroupId',
              isSlot: true,
              width: 150
            },
            {
              label: '维修技师',
              prop: 'repairTechnician',
              isSlot: true
            },
            {
              label: '费用预估',
              prop: 'wiPreAmount'
            },
            {
              label: '套餐/精品编码',
              prop: 'servicePackageCode'
            },
            {
              label: '是否委外',
              prop: 'isEntrust',
              isComponent: true,
              comps: [
                {
                  compKey: 'compKey8',
                  codeField: 'isEntrustCode',
                  textField: 'isEntrust',
                  disabled: false,
                  isAsync: true,
                  customObj: {
                    api: orgApis.whetherOutsourcing,
                    defOptionFields: ['isEntrustCode', 'isEntrust'],
                    selectType: '1'
                  },
                  component: () => import('@/components/org/commonSelect'),
                  rowFileds:
                      'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
                  type: 'dropdownList'
                }
              ]
            },
            {
              label: '备注',
              prop: 'note'
            }
          ],

      // 备件
      tableHeader_3_2: [
        {
          label: '备件编码',
          prop: 'partNo'
        },
        {
          label: '备件名称',
          prop: 'partName'
        },
        {
          label: '维修类型',
          prop: 'retRepairTypeName'
        },
        {
          label: '付费性质',
          prop: 'payKindName'
        },
        {
          label: '数量',
          prop: 'partQty',
          isComponent: true,
          align: 'center',
          width: 160,
          comps: [
            {
              compKey: 'compKey5',
              codeField: 'partQty',
              component: () =>
                import('@/components/se/commonInput/numberInput'),
              isInput: true,
              isAsync: true,
              width: 150,
              dataToObject: {
                min: 0.1
                // empty: true
              },
              align: 'center',
              rowFileds:
                'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
              disabled: true,
              isRequire: false,
              change: (val, comType, row) => this.changeRow(val, comType, row),
              type: 'Number'
            }
          ]
        },
        {
          label: '已出库数量',
          prop: 'outQty'
        },
        {
          label: '可用数量',
          prop: 'usableStockQty'
        },
        {
          label: '单价',
          prop: 'partPrice'
        },
        {
          label: '费用合计',
          prop: 'partAmount'
        },
        {
          label: '费用预估',
          prop: 'prePartAmount'
        },
        {
          label: '套餐/精品编码',
          prop: 'comboSaleCode'
        },
        {
          label: '是否委外',
          prop: 'isAssign',
          isComponent: true,
          comps: [
            {
              compKey: 'compKey6',
              codeField: 'isEntrustCode',
              textField: 'isEntrust',
              isAsync: true,
              customObj: {
                api: orgApis.whetherOutsourcing,
                defOptionFields: ['isEntrustCode', 'isEntrust'],
                selectType: '1'
              },
              component: () => import('@/components/org/commonSelect'),
              rowFileds:
                'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
              disabled: false,
              type: 'dropdownList'
            }
          ]
        },
        {
          label: '备注',
          prop: 'note'
        }
      ],

      tableHeader_3_3: [
        {
          label: '项目描述',
          prop: 'remark',
          isComponent: true,
          comps: [
            {
              compKey: 'remark',
              codeField: 'remark',
              component: () => import('@/components/org/commonInput'),
              rowFileds:
                'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
              disabled: false,
              isShowLabel: false,
              isInput: true
            }
          ]
        },
        {
          label: '其他项目',
          prop: 'otherAmountType'
        },
        {
          label: '付费性质',
          prop: 'payKindName'
        },
        {
          label: '维修类型',
          prop: 'retRepairTypeName'
        },
        {
          label: '费用合计',
          prop: 'otherAmount',
          width: 200,
          isComponent: true,
          comps: [
            {
              compKey: 'compKey5',
              codeField: 'otherAmount',
              component: () =>
                import('@/components/se/commonInput/priceNumInput'),
              isInput: true,
              dataToObject: {
                min: 0
                // empty: true
                // isformat: /^[0-9]*$/
              },
              change: (val, comType, row) => this.changeRow1(val, comType, row),
              rowFileds:
                'disabled:repairOrderStatusName-质检完成|disabled:repairOrderStatusName-收款|disabled:repairOrderStatusName-结算申请|disabled:repairOrderStatusName-已作废',
              isRequire: false,
              disabled: false,
              type: 'Number'
            }
          ]
        },
        {
          label: '套餐/精品编码',
          prop: 'servicePackageCode'
        }
      ],

      formInputs_4: [
        {
          compKey: 'key0',
          labelName: '索赔：',
          codeField: 'spTotal',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key1',
          labelName: '内部：',
          codeField: 'nbTotal',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key2',
          labelName: '保险：',
          codeField: 'bxTotal',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key3',
          labelName: '客户：',
          codeField: 'khTotal',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key4',
          labelName: '工时费：',
          codeField: 'wCoSts',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key5',
          labelName: '备件费：',
          codeField: 'pCoSts',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key6',
          labelName: '其他费用：',
          codeField: 'oCoSts',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'key7',
          labelName: '费用合计：',
          codeField: 'totals',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        }
      ],

      formField_5: {
        spTotal: '',
        nbTotal: '',
        bxTotal: '',
        khTotal: '',
        wCoSts: '',
        pCoSts: '',
        oCoSts: '',
        totals: ''
      },

      callbackObj: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelectChange: (selection) => {
          this.selectWi = selection
        }
      },

      callbackObj1: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelectChange: (selection) => {
          this.selectSpart = selection
        }
      },

      callbackObj2: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelectChange: (selection) => {
          this.selectOther = selection
        }
      },
      // 选择备件弹框数据
      spareSelectionRowData: {},
      timeSelectionRowData: {},
      // 权益查询
      equityQueryRowData: {},
      // 勾选获得表格数据
      selectOther: [],
      selectSpart: [],
      selectWi: []
    }
  },
  watch: {
    'formField_3_1.repairTypeName'(val) {
      if (val) {
        this.addPush = false
      } else {
        this.addPush = true
      }
    },

    // 监听VIN码
    'formField_1.vin'(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.queryCar()
      }
    },

    // 计算工时费用
    timeChooseArray(val) {
      let num = 0
      for (let i = 0; i < this.timeChooseArray.length; i++) {
        num +=
          ((this.timeChooseArray[i].wiPrice * 100) / 100) *
          this.timeChooseArray[i].saleWorkQty
        this.timeChooseArray[i].wiAmount = (
          ((this.timeChooseArray[i].wiPrice * 100) / 100) *
          this.timeChooseArray[i].saleWorkQty
        ).toFixed(2)
        this.timeChooseArray[i].wiPreAmount = this.timeChooseArray[i].wiAmount
      }
      this.formField_5.wCoSts = num.toFixed(2) // 计算工时费用
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    // 计算备件费用
    spareChooseArray(val) {
      this.spareNum = 0
      for (let i = 0; i < this.spareChooseArray.length; i++) {
        this.spareNum += (this.spareChooseArray[i].partAmount * 100) / 100
      }
      this.formField_5.pCoSts = this.spareNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    // 计算其他费用
    otherChooseArray(val) {
      let otherNum = 0
      for (let i = 0; i < this.otherChooseArray.length; i++) {
        otherNum += (this.otherChooseArray[i].otherAmount * 100) / 100
      }
      this.formField_5.oCoSts = otherNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    }
  },

  // 进入当前存在activated()函数的页面时，一进入页面就触发；可用于初始化页面数据
  async activated() {
    await this.maintainAll()
    await this.gmentModtions()
    if (this.$route.params.edit) {
      await this.queryOrderInfo()
      await this.maintenanceTime()
      this.repairPartList()
      this.repairOtherList()
    }
    if (this.$route.params.edit) {
      this.formField_1.vin = this.$route.params.vin
      this.queryCar()
    }
  },
  mounted() {
    this.loadwarehouseData()
    this.querySelect()
  },
  methods: {
    querySelect() {
      this.$requestAPI({
        apiUrl: orgApis.selectBillType.APIUrl,
        variables: {}
      }).then((res) => {
        if (res.result === '1') {
          const dataArry = res.rows.filter(item => {
            return item.billTypeName !== '新车PDI'
          })
          dataArry.map(item => {
            this.formInputs_2[9].options.push({
              label: item.billTypeName,
              value: item.billType
            })
          })
        }
      })
    },
    // 加载维修技师数据
    loadwarehouseData() {
      this.$requestAPI({
        apiUrl: orgApis.repairTeam.APIUrl,
        variables: {}
      })
        .then((res) => {
          if (res.result === '1') {
            this.warehouseOptions = res.rows
          } else {
            this.$message(res.msg ? res.msg : '')
          }
        })
        .catch((err) => {
          if (err.response.data.msg) {
            this.$message(err.response.data.msg)
          } else {
            this.$message(err.message)
          }
        })
    },
    wareHouseChange(val, scope) {
      this.$requestAPI({
        apiUrl: orgApis.repairArtificer.APIUrl,
        variables: {
          repairGroupId: val
        }
      })
        .then((res) => {
          if (res.result === '1') {
            this.$set(scope.row, 'optionsRepair', res.rows)
            scope.row.repairTechnician = ''
          } else {
            this.$message(res.msg ? res.msg : '')
          }
        })
        .catch((err) => {
          if (err.response.data.msg) {
            this.$message(err.response.data.msg)
          } else {
            this.$message(err.message)
          }
        })
    },

    // 选择列是否生效
    // 质检完成
    // getSelectable(row, index, tableRef) {
    //   if (
    //     this.formField_2.repairOrderStatus === '30'
    //   ) {
    //     if (row.isAdd === '1') {
    //       return true // 生效
    //     }
    //   } else {
    //     return true
    //   }
    // },
    // 选择列是否生效
    getSelectable(row, index, tableRef) {
      if (this.$route.params.repairOrderStatus === '30') {
        if (row.isAdd === '1') {
          return true // 生效
        }
      } else {
        return true
      }
    },
    /* -------------------------------------- 工单新增/修改 -------------------------------------- */
    // VIN带出数据及车主信息
    queryCar() {
      const that = this
      const info = {}
      info.vin = this.formField_1.vin
      info.isOtherCar = this.formField_1.isOtherCar
      if (info.isOtherCar === '0') {
        this.formField_4.scRecommendIte = ''
        request({
          url: '/mp/e3sh/aftersale/WorkOrderManagementService/carInforList.do',
          method: 'post',
          data: info
        }).then((res) => {
          that.carInfo = res.rows[0]
          for (const i in that.formField_1) {
            that.formField_1[i] = res.rows[0][i]
          }
          for (const i in that.formField_3) {
            that.formField_3[i] = res.rows[0][i]
          }
          that.formField_1.VIN = res.rows[0].vin
          // 上次维修项目建议
          request({
            url: '/mp/e3sh/aftersale/WorkOrderManagementService/lastTimeProposal.do',
            method: 'post',
            data: { vin: res.rows[0].vin }
          }).then((res) => {
            if (res.result === '1' && res.rows.length !== 0) {
              this.formField_4.scRecommendItem = res.rows[0].scRecommendItem
            } else if (res.result === '1' && res.rows.length === 0) {
              this.formField_4.scRecommendItem = ''
            }
          })
        })
      } else if (info.isOtherCar === '1') {
        // 他牌车
        request({
          url: 'mp/e3sh/aftersale/WorkOrderManagementService/carOtherInforList.do',
          method: 'post',
          data: info
        }).then((res) => {
          that.carInfo = res.rows[0]
          for (const i in that.formField_1) {
            that.formField_1[i] = res.rows[0][i]
          }
          for (const i in that.formField_3) {
            that.formField_3[i] = res.rows[0][i]
          }
          that.formField_1.VIN = res.rows[0].vin

          /* -------------------------------------- 客户描述 -------------------------------------- */

          // 上次维修项目建议
          request({
            url: '/mp/e3sh/aftersale/WorkOrderManagementService/lastTimeProposal.do',
            method: 'post',
            data: { vin: res.rows[0].vin }
          }).then((res) => {
            if (res.result === '1' && res.rows.length !== 0) {
              this.formField_4.scRecommendItem = res.rows[0].scRecommendItem
            } else if (res.result === '1' && res.rows.length === 0) {
              this.formField_4.scRecommendItem = ''
            }
          })
        })
      }
    },

    // 主查询-车辆信息--派工信息--车主信息--客户描述
    queryOrderInfo() {
      const that = this
      const queryObj = {
        type: 'mutation',
        apiConfig: orgApis.workOrderDetails,
        variables: {
          repairOrderCode: this.$route.params.repairOrderCode,
          repairOrderId: this.$route.params.repairOrderId
        }
      }
      var paramD = this.$getParams(queryObj)
      this.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          var res = response.rows
          this.billType = response.rows[1].billType
          // 新车PDI
          if (response.rows[1].billType === '31802') {
            this.formInputs_3_1[0].disabled = true
            this.formInputs_2[9].disabled = true
            this.isDel = true
            this.$requestAPI({
              apiUrl: orgApis.selectBillType.APIUrl,
              variables: {}
            }).then((res) => {
              if (res.result === '1') {
                const dataArry = res.rows.filter(item => {
                  return item.billTypeName === '新车PDI'
                })
                dataArry.map(item => {
                  this.formInputs_2[9].options.push({
                    label: item.billTypeName,
                    value: item.billType
                  })
                })
              }
            })
          }
          // 转车间
          if (response.rows[1].toWorkshop === '1') {
            this.formButtons[7].disabled = true
          }
          // 转车间
          if (response.rows[0].isTransparent === '0') {
            this.formButtons[7].disabled = true
          } else {
            this.formButtons[7].disabled = false
          }
          // 车辆信息
          for (const i in that.formField_1) {
            that.formField_1[i] = response.rows[1][i]
          }
          // 上次维修项目建议
          request({
            url: '/mp/e3sh/aftersale/WorkOrderManagementService/lastTimeProposal.do',
            method: 'post',
            data: { vin: this.formField_1.vin }
          }).then((res) => {
            if (res.result === '1' && res.rows.length !== 0) {
              this.formField_4.scRecommendItem = res.rows[0].scRecommendItem
            } else if (res.result === '1' && res.rows.length === 0) {
              this.formField_4.scRecommendItem = ''
            }
          })
          // 派工信息
          for (const i in that.formField_2) {
            that.formField_2[i] = response.rows[1][i]
            that.formField_2.empName = response.rows[1].empName
            that.formField_2.empId = response.rows[1].empId
          }
          console.log(that.formField_2)
          // 车主信息
          for (const i in that.formField_3) {
            that.formField_3[i] = response.rows[1][i]
          }
          // 客户描述
          for (const i in this.formField_4) {
            this.formField_4[i] = response.rows[1][i]
          }
          // 费用信息
          for (const i in this.formField_5) {
            this.formField_5[i] = response.rows[1][i]
          }
          this.formField_1.VIN = response.rows[1].vin
          this.formField_1.carLicense = response.rows[1].carLicense
          this.serviceDlrId = res[1].repairOrderId
          this.formList.ispick = res[1].ispick
          this.formList.isCarStore = res[1].isCarStore
          this.formList.isDelivery = res[1].isDelivery
          this.formList.isHelp = res[1].isHelp
          this.formList.isWait = res[1].isWait
          this.formList.isClean = res[1].isClean
          this.serviceActive(res[1].repairOrderId)
        }
      })
    },

    // 判断新增还是修改
    gmentModtions() {
      const that = this
      if (this.$route.params.add) {
        // 服务顾问
        this.$requestAPI({
          apiUrl: orgApis.empNameSelect.APIUrl,
          variables: {}
        }).then((res) => {
          this.formField_2.empName = res.rows[0].empName
        })
        this.formButtons[0].disabled = true // 作废
        this.formButtons[5].disabled = true // 维修历史
        this.formButtons[7].disabled = true // 转车间
        this.formButtons[8].disabled = true // 质检完成
        this.formButtons[9].disabled = true // 新增则电池追溯禁用
        this.formInputs_1[0].disabled = false
        this.formButtons[10].disabled = true
        // 派工信息是否禁用input
        that.formInputs_2[4].disabled = false
        that.formInputs_2[5].disabled = false
        that.formInputs_2[7].disabled = false
        that.formInputs_2[8].disabled = false
        // 车辆信息
        for (const i in that.formField_1) {
          that.formField_1[i] = ''
        }
        // 派工信息
        for (const i in that.formField_2) {
          that.formField_2[i] = ''
        }
        // 车主信息
        for (const i in that.formField_3) {
          that.formField_3[i] = ''
        }
        // 客户描述
        for (const i in that.formField_4) {
          that.formField_4[i] = ''
        }
        // 费用信息
        for (const i in that.formField_5) {
          that.formField_5[i] = ''
        }

        this.$refs['table_1'].list = []
        this.$refs['table_2'].list = []
        this.$refs['table_3_1'].list = []
        this.$refs['table_3_2'].list = []
        this.$refs['table_3_3'].list = []
      }

      if (this.$route.params.edit) {
        that.formInputs_2[4].disabled = true
        that.formInputs_2[7].disabled = true
        that.formInputs_2[8].disabled = true

        this.formButtons[0].disabled = false // 作废
        this.formButtons[5].disabled = false // 维修历史
        this.formButtons[8].disabled = false // 质检完成
        this.formInputs_1[0].disabled = true

        // 是否车主确认
        if (this.$route.params.appConfirm === '1') {
          this.formButtons[10].disabled = true
        }

        if (this.$route.params.repairOrderStatus === '0') {
          this.formButtons[8].disabled = false
        }
        if (this.$route.params.repairOrderStatus === '30') {
          // 质检完成
          this.isDel = true
          this.isOpenRepairGroup = true
          this.isOpenRepairTechnician = true
        }
        if (this.$route.params.repairOrderStatus === '40') {
          // 维修结算
          this.isDel = true
          this.formInputs_3_1[0].disabled = true
        }
        if (this.$route.params.repairOrderStatus === '50') {
          // 收款
          this.isDel = true
          this.isOpenRepairGroup = true
          this.isOpenRepairTechnician = true
          this.formInputs_3_1[0].disabled = true
          for (let i = 0; i < this.formButtons.length; i++) {
            this.formButtons[i].disabled = true
          }
          this.formInputs_1[9].disabled = true
          this.formInputs_2[2].disabled = true
          this.formInputs_2[3].disabled = true
          this.formInputs_2[5].disabled = true
          this.textareaInputs[0].disabled = true
          this.textareaInputs[2].disabled = true
        }
        // 已作废
        if (this.$route.params.repairOrderStatus === '-10') {
          for (let i = 0; i < this.formButtons.length; i++) {
            this.formButtons[i].disabled = true
          }
          this.isDel = true
          this.isOpenRepairGroup = true
          this.isOpenRepairTechnician = true
          this.formInputs_3_1[0].disabled = true
          this.formInputs_1[9].disabled = true
          this.formInputs_2[2].disabled = true
          this.formInputs_2[3].disabled = true
          this.formInputs_2[5].disabled = true
          this.textareaInputs[0].disabled = true
          this.textareaInputs[2].disabled = true
        } else {
          this.isDel = false
          this.isOpenRepairGroup = false
          this.isOpenRepairTechnician = false
          this.formInputs_3_1[0].disabled = false
          this.formInputs_1[9].disabled = false
          this.formInputs_2[2].disabled = false
          this.formInputs_2[3].disabled = false
          this.formInputs_2[5].disabled = false
          this.textareaInputs[0].disabled = false
          this.textareaInputs[2].disabled = false
        }
      }
    },

    // 保存
    saveAddEdit() {
      const that = this
      if (!Object.keys(this.$route.params).length) {
        this.$alert('切换之后页面之后部分数据已经清空，无法进行保存操作请重新进入当前页面。', '警告', {
          confirmButtonText: '确定',
          callback: action => {
            this.$store.commit('tagsView/DEL_VISITED_VIEW', {
              name: 'wExtensiceSubmit',
              path: '/aftermarketMange/maintenanceManagement/orderDetails'
            })
            that.$router.push({
              name: 'repairOrder',
              path: '/aftermarketMange/maintenanceManagement/repairOrder',
              params: { isOver: true }
            })
          }
        })
      }
      if (this.$route.params.add) {
        that.saveAdd()
      }
      if (this.$route.params.edit) {
        that.saveEdit()
      }
    },

    // 新增保存
    async saveAdd() {
      // console.log(this.$store.getters.orgInfo); // 勿删
      const that = this
      const info = {
        ...this.carInfo,
        ...this.formField_1,
        ...this.formField_2,
        ...this.formField_3,
        ...this.formField_4,
        ...this.formField_5,
        listMapActivity: []
      }
      info.empName = this.$store.getters.orgInfo.EMP_NAME
      info.empId = this.$store.getters.orgInfo.EMP_ID
      info.wiDueAmount = this.wiDueAmount
      info.partDueFee = this.partDueFee
      info.sumOtherDueAmount = this.sumOtherDueAmount
      info.repairDueAmount = this.repairDueAmount
      info.mileage = this.formField_1.mileage
      info.realMileage = this.formField_1.realMileage
      info.carLicense = this.formField_1.carLicense
      info.reserveOrderCode = this.reserveOrderCode
      this.$refs['table_1'].list.forEach(function(item, index) {
        info.listMapActivity.push({ actionId: item.actionCode })
      })
      info.listMapWi = this.$refs['table_3_1'].list
      info.listMapPart = this.$refs['table_3_2'].list
      info.listMapOther = this.$refs['table_3_3'].list

      // 其他费用合计验证
      const regNum = /^(\+)?\d+(\.\d+)?$/
      info.listMapOther.forEach((item) => {
        if (!regNum.test(item.otherAmount) && item.otherAmount !== '') {
          this.oflag = true
        }
      })

      if (!that.formField_1.VIN) {
        that.$message('请点击VIN选择车辆信息!')
        return false
      }
      if (!that.formField_2.repairTime) {
        that.$message('到店时间不能为空!')
        return false
      }
      if (!that.formField_2.preGetDate) {
        that.$message('预计交车时间不能为空!')
        return false
      }

      if (this.oflag) {
        this.$message('其他项目费用合计金额不能为负值！')
        this.oflag = false
        return false
      }

      await request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/addWorkOrder.do',
        method: 'post',
        data: info
      }).then((res) => {
        if (res.result === '1') {
          that.$message(res.msg)
          this.$store.commit('tagsView/DEL_VISITED_VIEW', {
            name: 'wExtensiceSubmit',
            path: '/aftermarketMange/maintenanceManagement/orderDetails'
          })
          that.$router.push({
            name: 'repairOrder',
            path: '/aftermarketMange/maintenanceManagement/repairOrder',
            params: { isOver: true }
          })
        } else {
          that.$message(res.msg)
        }
      })
    },

    // 修改保存
    async saveEdit() {
      console.log(this.$store.getters.orgInfo)
      const that = this
      this.spareChooseArray = this.$refs['table_3_2'].list
      const info = {
        ...this.formField_5,
        ...this.formField_2,
        listMapActivity: []
      }
      info.repairOrderId = this.$route.params.repairOrderId
      info.mileage = this.formField_1.mileage
      info.realMileage = this.formField_1.realMileage
      info.carLicense = this.formField_1.carLicense
      info.csDesc = this.formField_4.csDesc
      info.recommendItem = this.formField_4.recommendItem
      info.updateControlId = this.$route.params.updateControlId
      info.wiDueAmount = this.wiDueAmount
      info.partDueFee = this.partDueFee
      info.sumOtherDueAmount = this.sumOtherDueAmount
      info.repairDueAmount = this.repairDueAmount
      info.listMapWi = this.$refs['table_3_1'].list
      info.listMapPart = this.$refs['table_3_2'].list
      info.listMapOther = this.$refs['table_3_3'].list
      this.$refs['table_1'].list.forEach(function(item, index) {
        info.listMapActivity.push({ actionId: item.actionCode })
      })
      // 其他费用合计验证
      const regNum = /^(\+)?\d+(\.\d+)?$/
      info.listMapOther.forEach((item) => {
        if (!regNum.test(item.otherAmount) && item.otherAmount !== '') {
          this.oflag = true
        }
      })

      if (!that.formField_2.repairTime) {
        that.$message('到店时间不能为空!')
        return false
      }
      if (!that.formField_2.preGetDate) {
        that.$message('预计交车时间不能为空!')
        return false
      }

      if (this.oflag) {
        this.$message('其他项目费用合计金额不能为负值！')
        this.oflag = false
        return false
      }
      await request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/updWorkOrder.do',
        method: 'post',
        data: info
      }).then((res) => {
        if (res.result === '1') {
          that.$message(res.msg)
          this.$store.commit('tagsView/DEL_VISITED_VIEW', {
            name: 'wExtensiceSubmit',
            path: '/aftermarketMange/maintenanceManagement/orderDetails'
          })
          that.$router.push({
            name: 'repairOrder',
            path: '/aftermarketMange/maintenanceManagement/repairOrder',
            params: { isOver: true }
          })
        } else {
          that.$message(res.msg)
        }
      })
    },

    // 作废
    async becomeVoid() {
      const info = {}
      info.repairOrderId = this.$route.params.repairOrderId
      info.repairOrderCode = this.formField_2.repairOrderCode

      await request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/delWorkOrder.do',
        method: 'post',
        data: info
      }).then((res) => {
        if (res.result === '1') {
          this.$message(res.msg)
          this.$store.commit('tagsView/DEL_VISITED_VIEW', {
            name: 'wExtensiceSubmit',
            path: '/aftermarketMange/maintenanceManagement/orderDetails'
          })
          this.$router.push({
            name: 'repairOrder',
            path: '/aftermarketMange/maintenanceManagement/repairOrder',
            params: { isOver: true }
          })
        } else if (res.result === '0') {
          this.$message(res.msg)
        } else {
          this.$message(res.msg)
        }
      })
    },

    //
    /* -------------------------------------- 维修工时 -------------------------------------- */

    // 维修工时查询
    maintenanceTime() {
      request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/maintenanceTimeList.do',
        method: 'post',
        data: {
          repairOrderId: this.$route.params.repairOrderId,
          billType: this.billType == null ? '' : this.billType
        }
      }).then((res) => {
        res.rows.forEach((item) => {
          item.repairOrderStatusName = this.$route.params.repairOrderStatusName
          item.optionsRepair = [
            { empName: item.empName, repairTechnician: item.repairTechnician }
          ]
        })
        this.$refs['table_3_1'].list = res.rows
      })
    },

    // 工时新增弹窗
    addTimeChoose() {
      this.popupsVisibleTime = true
      this.timeSelectionRowData = this.formField_1
      this.chosenList = this.$refs['table_3_1'].list.map((o) => o['wiCode'])
    },

    // 获取父组件传值-工时选择
    getVal(val) {
      this.popupsVisibleTime = true
      this.disposeWis(val)
      val.forEach((item) => {
        item.isAdd = '1'
        if (
          item.isAdd === '1' &&
          this.$route.params.repairOrderStatus === '30'
        ) {
          this.isOpenRepairGroup = false
          this.isOpenRepairTechnician = false
          this.isDel = false
        }
      })
    },

    // 工时处理 (新增)
    disposeWis(val) {
      const that = this
      val.forEach((element) => {
        element.retRepairTypeName = this.formField_3_1.repairTypeName
        element.retRepairType = that.formField_3_1.repairTypeCode
        element.payKind = that.formField_3_1.payKind
        this.$refs['table_3_1'].list.push(element)
        that.payForNature(element)
      })
      this.timeChooseArray = this.$refs['table_3_1'].list
    },

    // 维修工时删除
    repairDelete() {
      if (this.$route.params.repairOrderStatus === '30') {
        for (let i = 0; i < this.selectWi.length; i++) {
          if (this.selectWi[i].isCanEdit === '1') {
            this.$message({
              message: '该工时已质检完成，不能删除！',
              duration: 1000
            })
            return
          }
        }
      }
      if (this.selectWi.length === 0) {
        this.$message({
          message: '未勾选删除项!',
          duration: 1000
        })
      } else {
        for (const i of this.selectWi) {
          this.$refs['table_3_1'].list = this.$refs['table_3_1'].list.filter(
            (item) => item !== i
          )
        }
        this.timeChooseArray = this.$refs['table_3_1'].list
      }
    },

    // 关闭弹窗
    close2() {
      this.popupsVisibleTime = false
      this.refreshTableKey1 += 1
    },

    //
    /* -------------------------------------- 维修备件 -------------------------------------- */

    // 维修备件查询
    repairPartList() {
      request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/repairPartList.do',
        method: 'post',
        data: {
          repairOrderId: this.$route.params.repairOrderId
        }
      }).then((res) => {
        res.rows.forEach((item) => {
          item.repairOrderStatusName = this.$route.params.repairOrderStatusName
        })
        this.$refs['table_3_2'].list = res.rows
      })
    },

    // 备件新增弹框
    SparePartsBounced() {
      this.spareSelectionPopupsVisible = true
      this.spareSelectionRowData = this.formField_1
      this.chosenPList = this.$refs['table_3_2'].list.map((o) => o['partNo'])
      this.payKindList.payKind = this.formField_3_1.payKind
      this.editPopupsState = 'spareSelection'
    },

    // 获取父组件传值-备件选择
    refundData2(refundData) {
      this.disposeSpa(refundData)
      refundData.forEach((item) => {
        if (item.outQty <= 0) {
          this.isDel = false
        }
        if (item.outQty > 0) {
          this.isDel = true
        }
        item.isAdd = '1'
        item.payKind = this.formField_3_1.payKind
        item.partAmount = (
          Number(item.partQty) * Number(item.partPrice)
        ).toFixed(2)
        item.prePartAmount = item.partAmount
      })
      this.spareChooseArray = refundData
      this.spareNum = 0
      for (let i = 0; i < this.spareChooseArray.length; i++) {
        this.spareNum += (this.spareChooseArray[i].partAmount * 100) / 100
      }
      this.formField_5.pCoSts = this.spareNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    // 备件处理 (新增)
    disposeSpa(refundData) {
      const that = this
      refundData.forEach((element) => {
        element.retRepairTypeName = this.formField_3_1.repairTypeName
        element.payKind = that.formField_3_1.payKind
        element.retRepairType = that.formField_3_1.repairTypeCode
        element.repairTypeCode = ''
        element.repairTypeName = ''
        this.$refs['table_3_2'].list.push(element)
        that.payForNature(element)
      })
      this.spareChooseArray = this.$refs['table_3_2'].list
    },

    // 维修备件删除
    partRepairDel() {
      // 判断是否含有已出库备件
      for (let i = 0; i < this.selectSpart.length; i++) {
        if (this.selectSpart[i].outQty > 0) {
          this.$message({
            message: '勾选项中含有已出库备件，请取消勾选!',
            duration: 1200
          })
          return
        }
      }

      if (this.selectSpart.length === 0) {
        this.$message({
          message: '未勾选删除项!',
          duration: 1000
        })
      } else {
        for (const i of this.selectSpart) {
          this.$refs['table_3_2'].list = this.$refs['table_3_2'].list.filter(
            (item) => item !== i
          )
        }
      }
      this.spareChooseArray = this.$refs['table_3_2'].list
    },

    // 关闭备件弹窗
    close() {
      this.spareSelectionPopupsVisible = false
      this.refreshTableKey2 += 1
    },

    //
    /* -------------------------------------- 维修其他项目 -------------------------------------- */

    // 其他项目查询
    repairOtherList() {
      request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/repairOtherList.do',
        method: 'post',
        data: {
          repairOrderId: this.$route.params.repairOrderId
        }
      }).then((res) => {
        res.rows.forEach((item) => {
          item.repairOrderStatusName = this.$route.params.repairOrderStatusName
        })
        this.$refs['table_3_3'].list = res.rows
        this.otherChooseArray = res.rows
      })
    },

    // 其他项目新增 弹窗
    addOtherProjects() {
      this.otherRowData.repairOrderId = this.$route.params.repairOrderId
      this.otherProjectsPopupsVisible = true
      this.chosenOList = this.$refs['table_3_3'].list.map(
        (o) => o['repairOtherId']
      )
      this.otherProjectsPopupsState = 'edit'
    },

    // 获取父组件传值-其他项目选择
    getList(refundData) {
      this.disposeOther(refundData)
      refundData.forEach((item) => {
        item.isAdd = '1'
      })
    },

    // 其他项目处理 (新增)
    disposeOther(refundData) {
      const that = this
      refundData.forEach((element) => {
        element.retRepairTypeName = that.formField_3_1.repairTypeName
        element.payKind = that.formField_3_1.payKind
        element.retRepairType = that.formField_3_1.repairTypeCode
        this.$refs['table_3_3'].list.push(element)
        that.payForNature(element)
      })
      this.otherChooseArray = this.$refs['table_3_3'].list
    },

    // 其他项目删除
    repairOtherListDelete() {
      if (this.selectOther.length === 0) {
        this.$message({
          message: '未勾选删除项!',
          duration: 1000
        })
      } else {
        for (const i of this.selectOther) {
          this.$refs['table_3_3'].list = this.$refs['table_3_3'].list.filter(
            (item) => item !== i
          )
        }
      }
      this.otherChooseArray = this.$refs['table_3_3'].list
    },

    // 关闭其他弹窗
    close3() {
      this.otherProjectsPopupsVisible = false
      this.refreshTableKey3 += 1
    },

    //
    /* -------------------------------------- 计算表格费用及费用合计费用 -------------------------------------- */

    // 计算
    changeNumber() {
      setTimeout(() => {
        this.timeChooseArray = this.$refs['table_3_1'].list
        this.spareChooseArray = this.$refs['table_3_2'].list
        this.otherChooseArray = this.$refs['table_3_3'].list
        let count = 0
        let neibu = 0
        let mange = 0
        let wiBack = 0
        let partBack = 0
        let otherBack = 0
        let allKu = 0
        for (let i = 0; i < this.timeChooseArray.length; i++) {
          if (this.timeChooseArray[i].payKindName == '索赔') {
            count += (this.timeChooseArray[i].wiAmount * 100) / 100
          } else if (this.timeChooseArray[i].payKindName == '客户') {
            wiBack += (this.timeChooseArray[i].wiAmount * 100) / 100
          } else if (this.timeChooseArray[i].payKindName == '保险') {
            neibu += (this.timeChooseArray[i].wiAmount * 100) / 100
          } else if (this.timeChooseArray[i].payKindName == '内部') {
            mange += (this.timeChooseArray[i].wiAmount * 100) / 100
          }
        }
        for (let i = 0; i < this.spareChooseArray.length; i++) {
          if (this.spareChooseArray[i].payKindName == '索赔') {
            count += (this.spareChooseArray[i].partAmount * 100) / 100
          } else if (this.spareChooseArray[i].payKindName == '客户') {
            partBack += (this.spareChooseArray[i].partAmount * 100) / 100
          } else if (this.spareChooseArray[i].payKindName == '保险') {
            neibu += (this.spareChooseArray[i].partAmount * 100) / 100
          } else if (this.spareChooseArray[i].payKindName == '内部') {
            mange += (this.spareChooseArray[i].partAmount * 100) / 100
          }
        }
        for (let i = 0; i < this.otherChooseArray.length; i++) {
          if (this.otherChooseArray[i].payKindName == '索赔') {
            count += (this.otherChooseArray[i].otherAmount * 100) / 100
          } else if (this.otherChooseArray[i].payKindName == '客户') {
            otherBack += (this.otherChooseArray[i].otherAmount * 100) / 100
          } else if (this.otherChooseArray[i].payKindName == '保险') {
            neibu += (this.otherChooseArray[i].otherAmount * 100) / 100
          } else if (this.otherChooseArray[i].payKindName == '内部') {
            mange += (this.otherChooseArray[i].otherAmount * 100) / 100
          }
        }
        this.formField_5.spTotal = count.toFixed(2)
        this.formField_5.khTotal = (wiBack + partBack + otherBack).toFixed(2)
        this.formField_5.nbTotal = mange.toFixed(2)
        this.formField_5.bxTotal = neibu.toFixed(2)
        this.wiDueAmount = wiBack.toFixed(2)
        this.partDueFee = partBack.toFixed(2)
        this.sumOtherDueAmount = otherBack.toFixed(2)
        allKu =
          (wiBack * 100) / 100 +
          (partBack * 100) / 100 +
          (otherBack * 100) / 100
        this.repairDueAmount = allKu.toFixed(2)
      }, 800)
    },

    // 计算备件费用
    changeRow(val, comType, row) {
      if (row.partQty < row.outQty) {
        this.$message({
          message: '备件数量必须大于等于已出库数量！',
          duration: 1000
        })
        row.partQty = row.outQty
        row.partAmount = (Number(row.partQty) * Number(row.partPrice)).toFixed(
          2
        )
        row.prePartAmount = row.partAmount
        this.tableHeader_3_2[4].comps[0].compKey =
          this.tableHeader_3_2[4].comps[0].compKey + this.$utils.generateId()
      }
      row.partAmount = (Number(val) * Number(row.partPrice)).toFixed(2)
      row.prePartAmount = row.partAmount
      this.$set(this.$refs['table_3_2'].list, comType, row)
      this.spareChooseArray = this.$refs['table_3_2'].list
      this.spareNum = 0
      for (let i = 0; i < this.spareChooseArray.length; i++) {
        this.spareNum += (this.spareChooseArray[i].partAmount * 100) / 100
      }
      this.formField_5.pCoSts = this.spareNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    // 计算其他费用
    changeRow1(val, comType, row) {
      if (!val) {
        row.otherAmount = 0
      }

      const regNum = /^(\+)?\d+(\.\d+)?$/
      if (!regNum.test(row.otherAmount) && row.otherAmount !== '') {
        this.$message('请输入正确的其他项目费用合计金额！')
        row.otherAmount = 0
        this.tableHeader_3_3[4].comps[0].compKey =
          this.tableHeader_3_2[4].comps[0].compKey + this.$utils.generateId()
      }

      this.otherNum = 0
      for (let i = 0; i < this.otherChooseArray.length; i++) {
        this.otherNum += (this.otherChooseArray[i].otherAmount * 100) / 100
      }
      this.changeNumber()
      this.formField_5.oCoSts = this.otherNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
    },

    // 判断付费性质
    payForNature(val) {
      if (
        val.retRepairTypeName == '免保' ||
        val.retRepairTypeName == 'PDI' ||
        val.retRepairTypeName == '索赔'
      ) {
        val.payKindName = '索赔'
      } else if (
        val.retRepairTypeName == '保养' ||
        val.retRepairTypeName == '机修' ||
        val.retRepairTypeName == '其他' ||
        val.retRepairTypeName == '延保'
      ) {
        val.payKindName = '客户'
      } else if (val.retRepairTypeName == '事故') {
        val.payKindName = '保险'
      } else if (
        val.retRepairTypeName == '外返' ||
        val.retRepairTypeName == '内返'
      ) {
        val.payKindName = '内部'
      }
    },

    //
    /* -------------------------------------- 服务活动 表格 -------------------------------------- */

    // 服务活动查询
    serviceActive(repairOrderId) {
      const info = {}
      info.repairOrderId = repairOrderId
      const queryObj = {
        apiConfig: orgApis.sActivitiesList,
        variables: info
      }
      var paramD = this.$getParams(queryObj)
      this.$requestAPI(paramD).then((response) => {
        this.$refs.table_1.list = response.rows
      })
    },

    // 服务活动删除
    serviceDelete(index) {
      this.$refs['table_1'].list.splice(index, 1)
    },

    //
    /* -------------------------------------- 保养套餐/商城精品  表格 -------------------------------------- */

    // 保养套餐/商城精品----查询
    maintainAll() {
      request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/setMealList.do',
        method: 'post',
        data: {
          repairOrderId: this.$route.params.repairOrderId
        }
      }).then((res) => {
        this.$refs['table_2'].list = res.rows
      })
    },

    // 保养套餐/商城精品----删除
    setMealDel(index) {
      const updateControlId = this.$refs.table_2.list[index].updateControlId
      const repairComboId = this.$refs.table_2.list[index].repairComboId
      request({
        url: '/mp/e3sh/aftersale/WorkOrderManagementService/setMealDel.do',
        method: 'post',
        data: {
          updateControlId: updateControlId,
          repairComboId: repairComboId
        }
      }).then((res) => {
        res.result === '1' ? this.$message(res.msg) : this.$message('操作失败')
      })
      this.maintainAll(this.$route.params.repairOrderId)
    },

    //
    /* -------------------------------------- 电池追溯 -------------------------------------- */

    // 电池追溯弹窗打开
    batteryOpen() {
      this.batteryData.repairOrderCode = this.formField_2.repairOrderCode
      this.batteryPopupsVisible = true
    },

    // 关闭电池追溯
    close9() {
      this.batteryPopupsVisible = false
    },

    //
    /* -------------------------------------- 质检完成 -------------------------------------- */

    // 质检完成
    async qualityInspection() {
      var dataList = this.$refs['table_3_1'].list.every((item) => {
        return item.repairWiId
      })
      if (dataList) {
        const that = this
        this.spareChooseArray = this.$refs['table_3_2'].list
        const info = { ...this.formField_5, listMapActivity: [] }
        info.repairOrderId = this.$route.params.repairOrderId
        info.repairOrderCode = this.$route.params.repairOrderCode
        info.mileage = this.formField_1.mileage
        info.realMileage = this.formField_1.realMileage
        info.carLicense = this.formField_1.carLicense
        info.empName = this.formField_2.empName
        info.repairMan = this.formField_2.repairMan
        info.repairTel = this.formField_2.repairTel
        info.preGetDate = this.formField_2.preGetDate
        info.repairOrderStatus = this.formField_2.repairOrderStatus
        info.csDesc = this.formField_4.csDesc
        info.recommendItem = this.formField_4.recommendItem
        info.wiDueAmount = this.wiDueAmount
        info.partDueFee = this.partDueFee

        info.sumOtherDueAmount = this.sumOtherDueAmount
        info.repairDueAmount = this.repairDueAmount
        info.listMapWi = this.$refs['table_3_1'].list
        info.listMapPart = this.$refs['table_3_2'].list
        info.listMapOther = this.$refs['table_3_3'].list

        this.$refs['table_1'].list.forEach(function(item, index) {
          info.listMapActivity.push({ actionId: item.actionCode })
        })

        const regNum = /^(\+)?\d+(\.\d+)?$/
        info.listMapOther.forEach((item) => {
          if (!regNum.test(item.otherAmount) && item.otherAmount !== '') {
            this.$message('其他项目费用合计金额不能为负值！')
            return false
          }
        })

        await request({
          url: '/mp/e3sh/aftersale/WorkOrderManagementService/selfTestComplete.do',
          method: 'post',
          data: info
        }).then((res) => {
          if (res.result === '1') {
            that.$message(res.msg)
            this.$store.commit('tagsView/DEL_VISITED_VIEW', {
              name: 'wExtensiceSubmit',
              path: '/aftermarketMange/maintenanceManagement/orderDetails'
            })
            that.$router.push({
              name: 'repairOrder',
              path: '/aftermarketMange/maintenanceManagement/repairOrder',
              params: { isOver: true }
            })
          } else {
            that.$message(res.msg)
          }
        })
      } else {
        this.$message('请先保存该工单！')
      }
    },

    //
    /* -------------------------------------- 转车间 -------------------------------------- */
    workOrderDispatch() {
      this.$requestAPI({
        apiUrl: orgApis.byPointTransferRoom.APIUrl,
        variables: {
          repairOrderCode: this.$route.params.repairOrderCode,
          repairOrderId: this.$route.params.repairOrderId
        }
      }).then((res) => {
        if (res.result === '1') {
          this.$message({
            message: res.msg,
            duration: 1000
          })
          this.$store.commit('tagsView/DEL_VISITED_VIEW', {
            name: 'wExtensiceSubmit',
            path: '/aftermarketMange/maintenanceManagement/orderDetails'
          })
          this.$router.push({
            name: 'repairOrder',
            path: '/aftermarketMange/maintenanceManagement/repairOrder',
            params: { isOver: true }
          })
        } else {
          this.$message({
            message: res.msg,
            duration: 1000
          })
        }
      })
    },

    //
    /* -------------------------------------- 预约 -------------------------------------- */

    // 预约页面传递过来的数据
    getAllList(val) {
      this.reserveOrderCode = val.reserveOrderCode
      this.disposeWis(val.wis)
      this.disposeSpa(val.parts)
      this.disposeOther(val.others)
      val.parts.forEach((item) => {
        item.partAmount = (
          Number(item.partQty) * Number(item.partPrice)
        ).toFixed(2)
        item.prePartAmount = item.partAmount
      })
      this.spareChooseArray = val.parts
      this.spareNum = 0
      for (let i = 0; i < this.spareChooseArray.length; i++) {
        this.spareNum += (this.spareChooseArray[i].partAmount * 100) / 100
      }
      this.formField_5.pCoSts = this.spareNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    // 预约
    subscribe() {
      if (this.formField_3_1.repairTypeName !== '') {
        this.appointmentTime.carLicense = this.formField_1.carLicense
        this.appointmentTime.custName = this.formField_3.custName
        this.appointmentTime.vin = this.formField_1.VIN
        this.isViewWindows = true
      } else {
        this.$message('请先选择维修类型')
      }
    },

    // 关闭预约
    close4() {
      this.isViewWindows = false
    },

    //
    /* -------------------------------------- 维修历史 -------------------------------------- */

    // 维修历史弹窗打开
    historyOpen() {
      this.rowData.carLicense = this.formField_1.carLicense
      this.rowData.custName = this.formField_3.custName
      this.rowData.vin = this.formField_1.VIN
      this.historyPopupsVisible = true
    },

    // 关闭维修历史弹窗
    close5() {
      this.historyPopupsVisible = false
    },

    //
    /* -------------------------------------- 权益查询 -------------------------------------- */
    // 权益查询
    equityQuery(index) {
      this.equityQueryVisible = true
      this.equityQueryRowData = this.$utils.deepCopy(
        this.$refs['multipleTable'].list[index]
      )
    },
    // 关闭权益弹窗
    close1() {
      this.equityQueryVisible = false
    },

    //
    /* -------------------------------------- 保养项目 -------------------------------------- */

    // 保养项目
    maintenanceProgram() {
      if (this.formField_3_1.repairTypeName !== '') {
        this.mImportPopupsVisible = true
        this.dataForForm = this.formField_1
        this.returnData()
      } else {
        this.$message({
          message: '请先选择维修类型！',
          duration: 1000
        })
      }
    },

    // 关闭保养项目弹窗
    closeMImport() {
      this.mImportPopupsVisible = false
    },

    // 保养项目传递过来得数据
    returnData(wiTable, partTable, otherTable) {
      this.disposeWis(wiTable)
      this.disposeSpa(partTable)
      this.disposeOther(otherTable)
      partTable.forEach((item) => {
        if (item.outQty <= 0) {
          this.isDel = false
        }
        if (item.outQty > 0) {
          this.isDel = true
        }
        item.partAmount = (
          Number(item.partQty) * Number(item.partPrice)
        ).toFixed(2)
        item.prePartAmount = item.partAmount
      })
      this.spareChooseArray = partTable
      this.spareNum = 0
      for (let i = 0; i < this.spareChooseArray.length; i++) {
        this.spareNum += (this.spareChooseArray[i].partAmount * 100) / 100
      }
      this.formField_5.pCoSts = this.spareNum.toFixed(2)
      this.formField_5.totals = (
        (this.formField_5.wCoSts * 100) / 100 +
        (this.formField_5.pCoSts * 100) / 100 +
        (this.formField_5.oCoSts * 100) / 100
      ).toFixed(2)
      this.changeNumber()
    },

    //
    /* -------------------------------------- 召回/服务活动 -------------------------------------- */

    // 召回/服务活动传递过来的数据
    getForwardList(event) {
      this.disposeWis(event.wiList)
      this.disposeSpa(event.paList)
      this.disposeOther(event.otherList)
    },

    // 召回/服务活动去重
    getServiceList(val) {
      if (this.$refs['table_1'].list.length != 0) {
        val.forEach((element) => {
          this.$refs['table_1'].list.some(
            (item) => item.actionCode == element.actionCode
          )
            ? ''
            : this.$refs['table_1'].list.push(element)
        })
      } else {
        val.forEach((element) => {
          this.$refs['table_1'].list.push(element)
        })
      }
    },

    // 召回/服务活动
    serviceAction() {
      this.recallData.CAR_LICENSE = this.formField_1.carLicense
      this.recallData.CUST_NAME = this.formField_3.custName
      this.recallData.VIN = this.formField_1.vin
      this.activePopupsVisible = true
    },

    // 关闭召回/服务活动
    close6() {
      this.activePopupsVisible = false
    },

    //
    /* -------------------------------------- 车主确认 -------------------------------------- */
    carConfirm() {
      this.$requestAPI({
        apiUrl: orgApis.appConfirm.APIUrl,
        variables: {
          repairOrderId: this.$route.params.repairOrderId
        }
      }).then((res) => {
        if (res.result === '1') {
          this.$message({
            message: res.msg,
            duration: 1000
          })
          this.$store.commit('tagsView/DEL_VISITED_VIEW', {
            name: 'wExtensiceSubmit',
            path: '/aftermarketMange/maintenanceManagement/orderDetails'
          })
          this.$router.push({
            name: 'repairOrder',
            path: '/aftermarketMange/maintenanceManagement/repairOrder',
            params: { isOver: true }
          })
        } else {
          this.$message({
            message: res.msg,
            duration: 1000
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-button {
  margin-left: 10px;
}
/deep/.el-input-number--small .el-input__inner {
  padding-right: 0;
}
/deep/.el-input-number .el-input__inner {
  padding-left: 0;
}
/deep/.el-table .el-input--small .el-input__inner {
  height: 26px;
}

.btns-container {
  // top: 45px;
  // right: 20rem;
  width: 100%;
  height: 30px;
  padding-right: 20px;
  background-color: #fff;
  .el-button {
    float: right;
  }
}
.btns-container:last-child button {
  margin-left: 10px;
}
.checkbox-wrapper {
  width: 100%;
  padding: 0 10px;
  background-color: #fff;
  .el-checkbox {
    float: right;
    margin-top: 10px;
  }
}
.textarea-header {
  width: 100%;
  height: 30px;
  background-color: #fff;
  &__item {
    width: calc(100% / 3);
    float: left;
  }
}
.mainten-select {
  width: 100%;
  height: 30px;
  padding: 0 20px;
  background-color: #fff;
}
.mainten-table__line {
  width: 100%;
  height: 30px;
  padding: 0 20px;
  line-height: 30px;
  background-color: #fff;
  &-info {
    float: left;
  }
  &-btns {
    float: right;
  }
}
.maodian {
  position: fixed;
  right: 1rem;
  top: 7rem;
}

.mark {
  padding-right: 190px;
  background: #ffffff;
}
/deep/.el-input-number--small {
  width: 160px;
}
</style>
